<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Configuration</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            background: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            max-width: 500px;
            width: 100%;
        }
        h1 {
            text-align: center;
            margin-bottom: 20px;
        }
        form {
            display: flex;
            flex-direction: column;
        }
        label {
            margin-bottom: 5px;
        }
        input {
            margin-bottom: 10px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        button {
            padding: 10px;
            background: #007BFF;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background: #0056b3;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Configuration Page</h1>
        <form id="configForm">
            <label for="databaseType">Database Type:</label>
            <input type="text" id="databaseType" name="database_type"><br>
            <label for="sqlitePath">SQLite Path:</label>
            <input type="text" id="sqlitePath" name="sqlite_path"><br>
            <label for="webPort">Web Port:</label>
            <input type="text" id="webPort" name="web_port"><br>
            <label for="mainStationURL">Main Station URL:</label>
            <input type="text" id="mainStationURL" name="main_station_url"><br>
            <label for="pollingInterval">Polling Interval:</label>
            <input type="text" id="pollingInterval" name="polling_interval"><br>
            <label for="maxThreads">Max Threads:</label>
            <input type="text" id="maxThreads" name="max_threads"><br>
            <label for="logRetentionDays">Log Retention Days:</label>
            <input type="text" id="logRetentionDays" name="log_retention_days"><br>
            <button type="button" onclick="submitConfig()">Submit</button>
        </form>
    </div>
    <script>
        function submitConfig() {
            const formData = new FormData(document.getElementById('configForm'));
            const config = {};
            formData.forEach((value, key) => {
                config[key] = value;
            });

            fetch('/config', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(config)
            }).then(response => {
                if (response.ok) {
                    alert('Config updated successfully');
                } else {
                    alert('Error updating config');
                }
            });
        }
    </script>
</body>
</html>
